﻿@*YoursLC有源低代码 Create:φ创建者Creatorφ 2022-05-07 19:30:35 添加或编辑-此文件放置于Views/Demo23/中*@

@using Think9.Models;
@model Think9.Models.Demo23Model
@{ ViewBag.Title = "Add";
	Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

@*Demo23主键和唯一*@
<style>
	/* 防止table的下拉列表被隐藏*/
	.layui-table-cell {
		overflow: visible;
	}
	.layui-table-box {
		overflow: visible;
	}
	.layui-table-body {
		overflow: visible; /* 与手机端冲突 */
	}
	/* 设置下拉框的高度与表格单元相同 */
	td .layui-form-select {
		margin-top: -3px;
		margin-left: -7px;
		margin-right: -7px;
	}
	.layui-table-view .layui-table th {
		overflow: hidden;
	}
</style>
<form class="layui-form" lay-filter="formUser">
<input style="display:none" id="_userid" value="@ViewBag.UserId">@*用户id*@
<input style="display:none" id="_attachmentId">@*附件id*@
<input style="display:none" id="_type" value="@ViewBag.Type">@*add或edit*@
<input style="display:none" id="prc_fid" value="@ViewBag.FId">@*当前流程编码*@
<input style="display:none" id="prc_id"  value="@ViewBag.PrcId">@*当前流程步骤id*@
<input style="display:none" id="prc_no"  value="@ViewBag.PrcNo">@*当前流程步骤编码*@
<input style="display:none" id="sys_plit" value="@ViewBag.Split">@*多选框字符分割*@
<input style="display:none" id="sys_listid" value="@ViewBag.ListId">
<input style="display:none" id="Pu_value">
<input style="display:none" id="Pu_tbid">
<input style="display:none" id="Pu_indexid">
<input style="display:none" id="Pu_id">
<input style="display:none" id="Pu_v">
<div class="layui-form">
 <div class="layui-form-item"  style="text-align: right;">
	<div class="layui-btn-group">
			@*<button type="button" class="layui-btn" id="sys_att">附件</button>*@
			<button type="button" class="layui-btn" lay-submit lay-filter="edit">保存</button>
			@*<button type="button" class="layui-btn" lay-submit lay-filter="next">转交</button>*@
			@*<button type="button" class="layui-btn" lay-submit lay-filter="finish">结束</button>*@
	 </div>
  </div>

	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label required">主键1</label>
			<div class="layui-input-block">
				<input type='text' name='inPrimaryKey1' id='inPrimaryKey1' autocomplete='off' class='layui-input'  maxlength='30'    lay-verify='required'  placeholder='主键1'>
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label required">主键2</label>
			<div class="layui-input-block">
				<input type='text' name='inPrimaryKey2' id='inPrimaryKey2' autocomplete='off' class='layui-input'  maxlength='30'    lay-verify='required'  placeholder='主键2'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label required">唯一键1</label>
			<div class="layui-input-block">
				<input type='text' name='inUniqueKey1' id='inUniqueKey1' autocomplete='off' class='layui-input'   maxlength='15'    lay-verify='required|integer'   placeholder='唯一键1'>
			</div>
		</div>
		<div class="layui-col-md6">
			<label class="layui-form-label required">唯一键2</label>
			<div class="layui-input-block">
				<input type='text' name='inUniqueKey2' id='inUniqueKey2' autocomplete='off' class='layui-input'  maxlength='30'    lay-verify='required'  placeholder='唯一键2'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label required">唯一键3</label>
			<div class="layui-input-block">
				<input type='text' name='inUniqueKey3' id='inUniqueKey3' autocomplete='off' class='layui-input'  maxlength='100'    lay-verify='required'  placeholder='唯一键3'>
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label required">唯一键4</label>
			<div class="layui-input-block">
				<input  name='inUniqueKey4' id='inUniqueKey4'  class='layui-input' autocomplete='off'  onClick="WdatePicker({ el: this,dateFmt: 'yyyy-MM-dd'})" placeholder='唯一键4'   lay-verify='required|date' >
			</div>
		</div>
	 </div>
</div>
	<div class="layui-table-box" id="div_tb_SubTable23">
		<table class="layui-hide" id="tb_SubTable23" lay-filter="tableFilter"> </table></div>
</form>
<script>
	layui.config({
		base: '/self_js/'  /*自定义的js文件 位于wwwroot/self_js文件夹中*/
	});
	layui.use(["form", "exLayer", "exUtils",  "table", "Demo23"], function () {
		let form = layui.form;
		let layer = layui.layer;
		let table = layui.table;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let mySelf = layui.Demo23;

		let $ = layui.$;
		form.render();

		getFormVal();//设置多选框和图片的显示--无多选框和图片可删除

		//根据步骤编码设置控件disabled
		mySelf.setStateByFlow($('#prc_no').val());
		//赋值--不包括多选框和图片
		form.val("formUser", {
			"inPrimaryKey1": "@Model.inPrimaryKey1"
			,"inPrimaryKey2": "@Model.inPrimaryKey2"
			,"inUniqueKey1": "@Model.inUniqueKey1"
			,"inUniqueKey2": "@Model.inUniqueKey2"
			,"inUniqueKey3": "@Model.inUniqueKey3"
			,"inUniqueKey4": showDate("@Model.inUniqueKey4")
		});
		//设置多选框和图片的显示
		function getFormVal() {


		}




		//点击保存按钮
		form.on("submit(edit)", function (data) {
			var _gridList = [];
			mySelf.foreachGridTable(_gridList);//遍历子表table取数
			exUtils.ajax('/Demo23/SaveData', 'post', {
				model: data.field, 'gridlist': _gridList, listid: $('#sys_listid').val(), prcno: $('#prc_no').val(), type: $('#_type').val(), att: $('#_attachmentId').val() }, true).done(function (response) {
				exLayer.greenTickMsg(response.message, function () {
				$(window.parent.document).find('#search').click();
				parent.layer.close(parent.layer.getFrameIndex(window.name));
			});
		}).fail(function (error) {
			console.log(error);
		});
			return false;
		});


			
		let tb_SubTable23 = table.render({
			elem: "#tb_SubTable23",
			url: "/Demo23/GetDataFromSubTable23?tbid=tb_SubTable23"+"&listid=" + $('#sys_listid').val()+"&from=" + $('#_type').val(),
			page: false,
			cols: [[
				{ field: "flag", title: "flag",  hide: true }
				,{ field: "v1", title: "主键", width: 190, templet: '#tb_SubTable23v1' }
				,{ field: "v2", title: "唯一", width: 190, templet: '#tb_SubTable23v2' }
				,{ field: "v3", title: "唯一", width: 190, templet: '#tb_SubTable23v3' }
				,{ field: "v4", title: "唯一", width: 190, templet: '#tb_SubTable23v4' }
				,{ title: "", align: "center", templet: "#addordelitem" }
			]],
			done: function (res, curr, count) {
				//手机给div设定宽度，要不表头显示不全
				if ($(window).width() < 768) {
					//$('th').hide();//表头隐藏
					$('#div_tb_SubTable23').css({ 'width': '860'});
				}
				$('.layui-table .layui-table-cell > span').css({ 'font-weight': 'bold' });
				console.log(res, curr, count);
				}
		
			});

	   table.on("tool(tableFilter)", function (obj) {
		let data = obj.data;
		switch (obj.event) {
			case "addGrid":
				addGrid(data);
				break;
			case "delGrid":
				delGrid(data);
				break;
		 }
		});

		//子表添加一条数据 无子表可删除
		function addGrid(data) {
			var _gridList = [];
			mySelf.getTopGridTable(_gridList);//只取首行
			exUtils.ajax("/Demo23/AddGrid", "post", { model: data.field, "list": _gridList, tbid: data.TbId, listid: $('#sys_listid').val() }, true).done(function (response) {
				$("#sys_listid").val(response.extra);
				tableRender(data.TbId);//子表数据刷新
			}).fail(function (error) {
				console.log(error);
			});
		}

		//子表删除一条数据 无子表可删除
		function delGrid(data) {
			exLayer.confirm("确定要删除吗？", function () {
				exUtils.ajax("/Demo23/DelGrid", "post", { flag: data.flag, listid: data.ListId }, true).done(function (response) {
					tableRender(data.TbId);//子表数据刷新
					 exUtils.tableSuccessMsg('删除成功！');
				}).fail(function (error) {
					console.log(error);
				});
			})
		}

		//子表刷新
		function tableRender(tbid) {
			if (tbid == "tb_SubTable23") {
				tb_SubTable23.reload({
					url: "/Demo23/GetDataFromSubTable23?tbid=tb_SubTable23" + "&listid=" + $('#sys_listid').val()+"&from=" + $('#_type').val()
				});
			}
		}

		//弹出页面关闭后为控件赋值 无弹出页面可删除
		$("#Pu_value").click(function () {
			mySelf.getValueFromPopUp();//控件赋值
			readValue();//执行数据读取
		});

		//数据读取
		function readValue() {
			var _gridList = [];
			mySelf.getSelectGridTable(_gridList, $('#Pu_tbid').val(), $('#Pu_id').val());

			var _controlsList = [];
			$.each($("form").serializeArray(), function (i, field) {
				_controlsList.push({ ControlID: field.name, ControlValue: field.value });
			  /*  alert(field.name + ":" + field.value);*/
			});
			//还要将禁用的控件push

			exUtils.ajax("/Demo23/AfterControlSelect", "post", { controlslist: _controlsList, "gridlist": _gridList, id: $('#Pu_id').val(), tbid: $('#Pu_tbid').val(), indexid: $('#Pu_indexid').val(), value: $('#Pu_value').val() }, true).done(function (response) {
				lists = response.list;
				console.log(lists);
				//使用后台返回的lists，为控件赋值
				mySelf.setValueByList(lists);

				form.render();//一定要加
			}).fail(function (error) {
				console.log(error);
			});

			return false;
		}

	});
</script>
<!-- 添加或删除 排除了统计行 -->
<script type='text/html' id='addordelitem'>
    {{#  if(d.Id >= 0){ }}
    {{#  if(d.Id == 0){ }}
    <a class='layui-btn layui-btn-xs' title='添加数据' lay-event='addGrid' id='addGrid'><i class='fa fa-plus'></i></a>
    {{#  } else{ }}
    <a class='layui-btn layui-btn-danger layui-btn-xs' title='删除数据' lay-event='delGrid' id='delGrid'><i class='fa fa-minus'></i></a>
    {{#  } }}
    {{#  } }}
</script>
<!-- 主键 -->
<script type="text/html" id="tb_SubTable23v1">
	<input type='text' name='tb_SubTable23v1' value = '{{d.v1_Exa}}' autocomplete='off' class='layui-input'  maxlength='30' style='height:30px;'  placeholder='主键'  {{d.v1_Lock}}>
</script>
<!-- 唯一 -->
<script type='text/html' id='tb_SubTable23v2'>
	<div class='layui-input-inline' style='width:150px;'>
		<select name='tb_SubTable23v2' {{d.v2_Lock}} lay-filter='tb_SubTable23Filter' data-value={{d.v2}}>
		<option value="">==请选择==</option>
		{{d.v2_Exa}}
		</select>
	</div>
</script>
<!-- 唯一 -->
<script type="text/html" id="tb_SubTable23v3">
	<input name='tb_SubTable23v3' value = '{{d.v3_Exa}}' autocomplete='off' onClick="WdatePicker({ el: this,dateFmt: 'yyyy-MM-dd'})" class='layui-input' style='height:30px;'  placeholder='唯一' {{d.v3_Lock}}>
</script>
<!-- 唯一 -->
<script type="text/html" id="tb_SubTable23v4">
	<input type='text' name='tb_SubTable23v4' value = '{{d.v4_Exa}}' autocomplete='off' class='layui-input'  maxlength='15' style='height:30px;'  placeholder='唯一'  {{d.v4_Lock}}>
</script>
<!-- 子表onclick调用 -->
<script>
	function PopUpSelectValue(tbid, indexid, id) {
		var url = '/Demo23/PopUpSelectValue?';
		PopSelectValue(tbid, indexid, id, url);
	}
	function PopUpImgUplaod(tbid, indexid, id, fname) {
		PopImgUplaod2(tbid, indexid, id, fname);
	}
</script>